package com.hy.mydesktop.client.mvc.base;

import java.util.List;

import com.extjs.gxt.ui.client.event.EventType;
import com.extjs.gxt.ui.client.mvc.AppEvent;
import com.extjs.gxt.ui.client.mvc.Controller;
import com.extjs.gxt.ui.client.mvc.View;
import com.extjs.gxt.ui.client.widget.Component;
import com.google.gwt.user.client.ui.Widget;
import com.hy.mydesktop.shared.persistence.domain.gxt.GxtComponentMetaNodeModel;
import com.hy.mydesktop.shared.util.log.MyLoggerUtil;

/**
 * 
 * <ul>
 * <li>开发作者：花宏宇</li>
 * <li>设计日期：2010-9-16；时间：上午11:27:11</li>
 * <li>类型名称：BaseController</li>
 * <li>设计目的：对Controller，进行封装</li>
 * </ul>
 * <ul>
 * <b>修订编号：</b>
 * <li>修订日期：</li>
 * <li>修订作者：</li>
 * <li>修订原因：</li>
 * <li>修订内容：</li>
 * </ul>
 */
public class BaseController extends Controller {
	
	public BaseController() {
		super();
		//printControllerForInit(T);
	}

	/**
	 * 创建控件，并创建控件对应的视图view
	 */
	@Override
	public void initialize() {
		super.initialize();
	}

	public void setIinitialized (Boolean initialized){
		super.initialized=true;
	}
	
	private GxtComponentMetaNodeModel gxtComponentMetaNodeModel;
	
	private Boolean initSelfComponent = true;

	private Presenter presenter;
	
	public Presenter getPresenter() {
		return presenter;
	}
	
	public void  setPresenter( Presenter presenter) {
		this.presenter  =presenter;
	}

	private View view;
	/**
	 * 定义Controller对应的View的标识信息
	 */
	private String viewData;
	/**
	 * 定义Controller的唯一标识
	 */
	private String id ;
	/**
	 * 定义Controller的除了标识之外的其他一些信息，如，子节点的信息
	 */
	private String controllerData;
	/*private Widget component;
	
	public Widget getComponet() {
		return component;
	}

	public void setComponet(Widget componet) {
		this.component = componet;
	}*/

	public Boolean isInitSelfComponent() {
		return initSelfComponent;
	}
	
	public void setInitSelfComponent(Boolean initSelfComponent) {
		this.initSelfComponent = initSelfComponent;
	}
	
	public String getControllerData() {
		return controllerData;
	}

	public void setControllerData(String controllerData) {
		this.controllerData = controllerData;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getViewData() {
		return viewData;
	}

	public void setViewData(String viewData) {
		this.viewData = viewData;
	}

	public View getView() {
		return view;
	}

	public void setView(View view) {
		this.view = view;
	}

	@Override
	public void handleEvent(AppEvent event) {
	}
	
	/**
	 * 
	 * <ul>
	 * <li>方法含义：对Controller及其子类，注册事件</li>
	 * <li>方法作者：花宏宇</li>
	 * <li>编写日期：2010-9-16；时间：下午上午11:27:56</li>
	 * </ul>
	 * <ul>
	 * <b>修订编号：</b>
	 * <li>修订日期：</li>
	 * <li>修订作者：</li>
	 * <li>修订原因：</li>
	 * <li>修订内容：</li>
	 * </ul>
	 * @param types
	 */
	public  void addRegisterEventType(EventType types) {
		super.registerEventTypes(types);
	}
	
	public Controller getParent() {
//		return (BaseController)super.parent;
		return super.parent;
	}
	
	public List<Controller> getChildren() {
		return super.children;
	}
	

	public GxtComponentMetaNodeModel getGxtComponentMetaNodeModel() {
		return gxtComponentMetaNodeModel;
	}

	public void setGxtComponentMetaNodeModel(
			GxtComponentMetaNodeModel gxtComponentMetaNodeModel) {
		this.gxtComponentMetaNodeModel = gxtComponentMetaNodeModel;
	}
	
	protected void printControllerForInit(Class className) {
		MyLoggerUtil.printControllerDebugForInit(className);

	}
	
	protected void buildComponentStructure(BaseController controller,Component component) {
		if (this.getParent()==null||this.getParent().equals("")) {
			MyLoggerUtil.printWarn(getClass(), "当前Controller["+controller.getClass().getName()+"],没有parent，控件不能构建结构！");
		}else {
			// 构建控件的树形结构
			((BaseController)this.getParent()).getPresenter().getDisplay().add(component);

		}
	}

}
